<template>
	<view class="columnbox wdh-100 content">
		<view class="rowbox wdh-100 type-box">
			<view @click="setType(item)" class="rowbox one-type" :class="{'sel-type':item.title==curtype}"
				v-for="(item,index) in typeList" :key='index'>{{item.title}}</view>
		</view>
		<template v-if="curtype=='中药处方'">
			<view class="columnbox wdh-100 one-info">
				<view class="rowbox wdh-100 spb">
					<view class="q-title columnbox als">
						<view>诊断</view>
						<view class="q-line"></view>
					</view>
					<view class="rowbox" style="color: #dddddd;">
						<!-- <view class="def-col set-btn">问诊单</view>｜ -->
						<view class="def-col set-btn" @click="showBingLi">查看病例</view>｜
						<view class="def-col set-btn" @click="writeThink">写思路</view>
					</view>
				</view>
				<view class="wdh-100 userinfo" v-if="user">
					患者：{{user.name}} {{user.sex==1?'男':'女'}} {{age}}岁
				</view>
				<view class="rowbox wdh-100 userinfo jus">
					辨病：<view class="columnbox sel-input-box" @click="inputChoose('zhongyao','bianbing')">
						<view class="u-input ">
							<text v-if="bianbing==''" class="wdh-100 reg-pl">需与实体医疗机构病例同病种</text>
							<text v-else class="wdh-100">
								{{bianbing}}
							</text>
						</view>
						<!-- <input @blur="hideSelect" @focus="showSelect" @input="searchSelect" v-model="bianbing"
							placeholder-class="reg-pl" class="u-input" placeholder="需与实体医疗机构病例同病种" />
						<scroll-view scroll-y class="wdh-100 select-input-scroll"
							v-if="selectInputFlag&&selectInputList.length>0">
							<view v-for="(item,index) in selectInputList" :key='index'
								@click="chooseBianbing(item.name)" class="rowbox wdh-100 one-select jus">{{item.name}}
							</view>
						</scroll-view> -->
					</view>
				</view>
				<view class="rowbox wdh-100 userinfo jus" @click="inputChoose('zhongyao','bianzheng')">
					辨证：
					<view class="u-input">
						<text v-if="bianzheng==''" class="wdh-100 reg-pl">请填写患者辨证</text>
						<text v-else class="wdh-100">
							{{bianzheng}}
						</text>
					</view>

					<!-- <input v-model="bianzheng" placeholder-class="reg-pl" class="u-input" placeholder="请填写患者辨证" /> -->
				</view>
				<!-- 处方 -->
				<!-- <view v-if="chufang==''" @click="exportChuFang" class="def-bgcol jx-btn" style="margin-top: 40rpx;">+
                    填写处方
                </view> -->
				<template v-if="storeList.length>0">
					<view class="rowbox wdh-100 spb store-box" @click="changeStore">
						<view class="rowbox">
							<image class="store-img" :src="storeList[curStore].logo" mode="aspectFill"></image>
							<view class="store-name">{{storeList[curStore].name||'暂无药房名称'}}</view>
						</view>
						<view class="rowbox def-col change-store">切换药店
							<view style="margin-left: 4rpx;">
								<u-icon name="arrow-right" size="24rpx" color="#00b6b2"></u-icon>
							</view>
						</view>
					</view>
					<view class="rowbox wdh-100 spb als" style="margin-top: 40rpx;">
						<image mode="aspectFill" class="cf-img"
							src="https://img2.baidu.com/it/u=4273482966,3520658106&fm=253&fmt=auto&app=138&f=JPEG?w=640&h=427">
						</image>
						<view class="columnbox als cf-jx">
							<view class="cf-jx-name" v-if="jixing!=''">{{jixing.jixing}}</view>
							<view v-else>请选择剂型</view>
							<view class="rowbox cf-jx-jgmx" @click="showDetailPrice">价格明细
								<u-icon name="arrow-right" size="20rpx"></u-icon>
							</view>
						</view>
						<picker @change="jxChange" mode="selector" :range="jxList" range-key="name">
							<view class="def-bgcol change-btn">选择剂型</view>
						</picker>
					</view>
					<view class="rowbox wdh-100 jus" style="margin-top: 40rpx;color: #dddddd;">
						<view class="def-col set-btn" @click="exportChuFang">填写处方</view>
						<text style="margin:0 20rpx;">｜</text>
						<view class="def-col set-btn" @click="saveModel">存模版</view>
						<text style="margin:0 20rpx;">｜</text>
						<view class="def-col set-btn" @click="clearChufang">清空处方</view>
					</view>
					<view class="columnbox wdh-100 manage-box">
						<view class="rowbox wdh-100 cf-name">
							Rp：<!-- <input v-model="chufang.name" placeholder="请输入" /> -->
						</view>
						<view class="yf-box" v-if="chufang.cfList&&chufang.cfList.length>0">
							<!-- <view class="wdh-100 wz-detail">
								<text style="margin-right: 20rpx;" v-for="(item,index) in chufang.cfList"
									:key='index'>{{item}}</text>
							</view> -->
							<view class="wdh-100 wz-detail">
								<view v-for="(item,index) in ycList" :key='index'
									style="margin-right: 20rpx;margin-bottom: 10rpx;">
									{{item.chinesedrug}}{{item.gram}}g
								</view>
							</view>
							<view class="wdh-100 wz-detail" v-if="noYcList.length>0"
								style="margin-top: 20rpx;color: #de101b;">
								<view style="margin-bottom: 20rpx;">
									*药店缺药：
								</view>
								<view v-for="(item,index) in noYcList" :key='index'
									style="margin-right: 10rpx;margin-bottom: 10rpx;">
									{{item.chinesedrug}}
								</view>
							</view>
						</view>
					</view>
					<view class="def-col rowbox edit-yc-btn" @click="editYaocai">编辑药材</view>
				</template>
			</view>
			<!-- 用法 -->
			<view class="columnbox wdh-100 one-info">
				<view class="rowbox wdh-100 spb">
					<view class="q-title columnbox als">
						<view>用法</view>
						<view class="q-line"></view>
					</view>
					<view class="rowbox" style="color: #dddddd;">
						<view class="def-col set-btn" @click="specialWrite=false" v-if="specialWrite">切换回正常写法</view>
						<view class="def-col set-btn" v-else @click="specialWrite=true">用特殊写法开药</view>
					</view>
				</view>
				<view class="rowbox wdh-100 jus">
					<view @click="curyongfa=item" class="rowbox one-yongfa" :class='{"sel-yongfa":item==curyongfa}'
						v-for="(item,index) in yongfaList" :key='index'>{{item}}</view>
				</view>
				<!-- 特殊写法 -->
				<template v-if="specialWrite">
					<view class="rowbox wdh-100 jus yongliang-box">
						<view>共</view>
						<input v-model="ji" type="number" placeholder-class="reg-pl" placeholder="请输入" />剂，共
						<text v-if="curyongfa=='内服'">服</text><text v-else>用</text>
						<input v-model="day" type="number" placeholder-class="reg-pl" placeholder="请输入" />日,
					</view>
					<view class="rowbox wdh-100 jus yongliang-box">
						<view>每日分</view>
						<input v-model="ci" type="number" placeholder-class="reg-pl" placeholder="请输入" />次<text
							v-if="curyongfa=='内服'">服用</text><text v-else>使用</text> ,
					</view>
				</template>
				<!-- 正常写法 -->
				<template v-else>
					<view class="rowbox wdh-100 jus yongliang-box">
						<view>共</view>
						<input type="number" v-model="ji" placeholder-class="reg-pl" placeholder="请输入" />剂，每日<input
							type="number" v-model="day" placeholder-class="reg-pl" placeholder="请输入" />剂,
					</view>
					<view class="rowbox wdh-100 jus yongliang-box">
						<view>1剂分</view>
						<input v-model="ci" type="number" placeholder-class="reg-pl" placeholder="请输入" />次
						<text v-if="curyongfa=='内服'">服用</text><text v-else>使用</text>
						,
					</view>
				</template>

				<view class="rowbox wdh-100 jus yongliang-box">
					<view>医嘱提醒</view>
					<view class="rowbox yz-input-box jus" @click="inputChoose('zhongyao','yizhu')"
						style="width: 470rpx;">
						<text class="wdh-100" v-if="title!=''">{{title}}</text>
						<text class="wdh-100 reg-pl" v-else>{{curyongfa=='内服'?"用药禁忌,时间等":"填写外用药使用方法,必填"}}</text>
					</view>
					<!-- <input v-model="title" v-if="curyongfa=='内服'" style="width: 470rpx;" placeholder-class="reg-pl"
						placeholder="用药禁忌,时间等" />
					<input v-model="title" v-else style="width: 470rpx;" placeholder-class="reg-pl"
						placeholder="填写外用药使用方法,必填" /> -->
				</view>
			</view>
			<!-- 设置 -->
			<view class="columnbox wdh-100 one-info">
				<view class="rowbox wdh-100 spb">
					<view class="q-title columnbox als">
						<view>设置</view>
						<view class="q-line"></view>
					</view>
				</view>
				<view class="rowbox wdh-100 userinfo jus">
					诊金：<input v-model="zhenjin" type="digit" placeholder-class="reg-pl" class="u-input"
						placeholder="将在支付明细中列出" />
				</view>
				<view class="rowbox wdh-100 userinfo jus">
					购药前可见处方：<radio-group @change="chufangKejian=$event.detail.value" v-model="chufangKejian"
						style="transform: scale(.9);">
						<radio style="margin-right: 40rpx;" value="1" :checked="chufangKejian=='1'" color="#00b6b2">是
						</radio>
						<radio value="2" :checked="chufangKejian=='2'" color="#00b6b2">否
						</radio>
					</radio-group>
				</view>
				<view class="rowbox wdh-100 userinfo jus">
					为患者预约复诊：
					<view style="width: 370rpx;" class="rowbox u-input jus" @click="fuzhenDateflag=true">
						<text class="reg-pl" v-if="fuzhenDate==''">点此设置下次复诊
						</text>
						<view v-else>{{fuzhenDate}}</view>
					</view>
				</view>
				<view class="set-box wdh-100">* 设置后，患者购药时可购买下次复诊</view>
			</view>
			<!-- 明细展开 -->
			<view class="columnbox wdh-100 one-info">
				<view class="rowbox wdh-100 spb">
					<view class="q-title columnbox als">
						<view>明细</view>
						<view class="q-line"></view>
					</view>
					<view class="rowbox" style="color: #dddddd;">
						<view v-if="detailOpen" class="def-col set-btn" @click="detailOpen=false">隐藏明细</view>
						<view v-else class="def-col set-btn" @click="detailOpen=true">展开查看明细</view>
					</view>
				</view>
				<template v-if="detailOpen">
					<view class="rowbox wdh-100 spb one-jgmx">
						<view>药费</view>
						<view>¥{{(ycPrice*ji).toFixed(2)}}</view>
					</view>
					<view class="rowbox wdh-100 spb one-jgmx">
						<view>诊金</view>
						<view>¥{{zhenjin||0}}</view>
					</view>
					<view class="rowbox wdh-100 spb one-jgmx">
						<view>问诊预约</view>
						<view>¥0</view>
					</view>
					<view class="rowbox wdh-100 spb one-jgmx">
						<view>总计</view>
						<!-- <view>¥{{totalPrice}}</view> -->
						{{(zhenjin*1 + ycPrice*ji*1).toFixed(2)}}
					</view>
				</template>
			</view>
			<view style="height: 200rpx;width: 100%;"></view>
			<view class="rowbox wdh-100 bottom-box">
				<template v-if="kfid==''||reOrder">
					<view v-if="submitflag" style="background: #f6f7fb;color:  #96949e;"
						class="def-bgcol rowbox send-btn">
						确认发送给患者</view>
					<view v-else class="def-bgcol rowbox send-btn" @click="submitInfo">签名确认并发送给患者</view>
				</template>
				<template v-else>
					<view v-if="submitflag" style="background: #f6f7fb;color:  #96949e;"
						class="def-bgcol rowbox send-btn">
						保存修改</view>
					<view v-else class="def-bgcol rowbox send-btn" @click="updateZhongyao">保存修改</view>
				</template>
			</view>
		</template>
		<template v-else>
			<view class="columnbox wdh-100 one-info">
				<view class="rowbox wdh-100 spb">
					<view class="q-title columnbox als">
						<view>主诉</view>
						<view class="q-line"></view>
					</view>
				</view>
				<view class="rowbox wdh-100 userinfo jus" @click="inputChoose('xiyao','zhusu')">
					<view class="u-input" style="width: 100%;">
						<text v-if="zhusu==''" class="wdh-100 reg-pl">请输入患者主诉</text>
						<text v-else class="wdh-100">
							{{zhusu}}
						</text>
					</view>
					<!-- <input v-model="zhusu" placeholder-class="reg-pl" class="u-input" style="width: 100%;"
						placeholder="请输入患者主诉" /> -->
				</view>
			</view>
			<view class="columnbox wdh-100 one-info">
				<view class="rowbox wdh-100 spb">
					<view class="q-title columnbox als">
						<view>处方信息</view>
						<view class="q-line"></view>
					</view>
					<view class="rowbox" style="color: #dddddd;" @click="chooseWestModel">
						<view class="def-col set-btn">使用处方模版</view>
					</view>
				</view>
				<view class="rowbox wdh-100 userinfo spb" @click="inputChoose('xiyao','bianbing')">
					疾病诊断：
					<view class="columnbox sel-input-box">
						<view class="u-input" style="width: 470rpx;">
							<text v-if="bianbing==''" class="wdh-100 reg-pl">请输入疾病诊断</text>
							<text v-else class="wdh-100">
								{{bianbing}}
							</text>
						</view>
						<!-- <input @blur="hideSelect" @focus="showSelect" @input="searchSelect" v-model="bianbing"
							placeholder-class="reg-pl" class="u-input" style="width: 470rpx;" placeholder="请输入疾病诊断" />
						<scroll-view scroll-y class="wdh-100 select-input-scroll"
							v-if="selectInputFlag&&selectInputList.length>0">
							<view v-for="(item,index) in selectInputList" :key='index'
								@click="chooseBianbing(item.name)" class="rowbox wdh-100 one-select jus">{{item.name}}
							</view>
						</scroll-view> -->
					</view>
				</view>
			</view>
			<view class="columnbox wdh-100 one-info">
				<view class="rowbox wdh-100 spb">
					<view class="q-title columnbox als">
						<view>Rp</view>
						<view class="q-line"></view>
					</view>
					<!-- <view class="rowbox" style="color: #dddddd;">
						<view class="def-col set-btn" style="color: #96949e;">建议用药（限5种）</view>
					</view> -->
				</view>
				<view v-for="(item,index) in infoList" :key='index' class="columnbox wdh-100 med-info">
					<view class="rowbox wdh-100 spb med-title">
						<view>
							药品{{index+1}}
						</view>
						<view class="rowbox del-btn" @click="deletMedicine(index)">删除</view>
					</view>
					<view class="rowbox spb med-box" @click="chooseUse(item,index)">
						<image v-if="item.image" :src="item.image.split(',')[0]" mode="aspectFill" class="m-img">
						</image>
						<view class="columnbox als m-detail">
							<view class="m-name wdh-100 rowbox spb">
								<view style="width: 400rpx;" class="textovflow">{{item.name}}</view>
								<view class="m-desc" style="white-space: nowrap;" v-if="item.use">x {{item.use.num}}
								</view>
							</view>
							<view class="m-desc">{{item.guige}}</view>
							<view class="m-desc rowbox wdh-100 spb">
								用法用量：
								<text v-if="item.use">
									{{item.use.yongfa.name}};{{item.use.pinci.name}};{{item.use.yongliang}}{{item.use.ylunit.name}};用药{{item.use.daynum}}天
								</text>
								<u-icon name="arrow-right" size="24rpx"></u-icon>
							</view>
						</view>
					</view>
				</view>
				<view v-if="infoList.length<5" class="rowbox wdh-100 add-btn" @click="addMedicine">+添加药品</view>
				<view class="rowbox wdh-100 userinfo jus">
					医嘱事项（选填）
				</view>
				<view class="rowbox u-input" style="width: 100%; margin-top: 20rpx;"
					@click="inputChoose('xiyao','yizhu')">
					<view class=" u-input" style="width: 100%;">
						<text v-if="yizhu==''" class="wdh-100 reg-pl">请输入医嘱事项</text>
						<text v-else class="wdh-100">
							{{yizhu}}
						</text>
					</view>
					<!-- <textarea v-model="yizhu" placeholder="请输入医嘱事项" auto-height class="u-input"
						style="width: 100%;padding: 0;" placeholder-class="reg-pl"></textarea> -->
				</view>
			</view>
			<view class="columnbox wdh-100 one-info">
				<view class="rowbox wdh-100 spb">
					<view class="q-title columnbox als">
						<view>价格（不含邮费）</view>
						<view class="q-line"></view>
					</view>
					<view class="q-title">¥{{totalPrice}}</view>
				</view>
				<view class="def-col set-btn wdh-100" style="color: #96949e;">以上为参考价格，实际以患者下单为准</view>
			</view>
			<view style="height: 200rpx;width: 100%;"></view>
			<view class="rowbox wdh-100 bottom-box">
				<view class="rowbox draft-btn" @click="saveWestMedicineTem">保存模版</view>
				<template v-if="kfid==''||reOrder">
					<view v-if="submitflag" style="background: #f6f7fb;color:  #96949e;"
						class="def-bgcol rowbox send-btn">
						确认发送给患者</view>
					<view v-else class="def-bgcol rowbox send-btn" @click="submitInfoWestMedicine">签名确认并发送给患者</view>
				</template>
				<template v-else>
					<view v-if="submitflag" style="background: #f6f7fb;color:  #96949e;"
						class="def-bgcol rowbox send-btn">
						保存修改</view>
					<view v-else class="def-bgcol rowbox send-btn" @click="updateXiyao">保存修改</view>
				</template>
			</view>
		</template>
		<!-- 价格明细 -->
		<u-popup mode="bottom" :show="detailPriceFlag" round="10" closeable @close="detailPriceFlag=false">
			<view class="jgmx-box columnbox">
				<view class="rowbox wdh-100 spb">
					<view class="q-title columnbox als">
						<view>共{{detailPriceList.length}}味药，共{{ycPrice}}元</view>
						<view class="q-line"></view>
					</view>
				</view>
				<scroll-view scroll-y class="wdh-100" style="height: 50vh;margin-top: 20rpx;">
					<view class="rowbox wdh-100 spb one-jgmx" v-for="(item,index) in detailPriceList" :key='index'>
						<view>{{item.name}}</view>
						<view>{{item.gram}}克*¥{{item.price}}=¥{{item.gram*item.price}}</view>
					</view>
				</scroll-view>
			</view>
		</u-popup>
		<!-- 选择复诊日期 -->
		<u-calendar @confirm="confirmFuzhenDate" :show="fuzhenDateflag" color="#00b6b2"
			@close="fuzhenDateflag=false"></u-calendar>

		<!-- 选择药店 -->
		<u-popup mode="bottom" :show='storeFlag' :duration="100" @close="storeFlag=false" round="20rpx" closeable>
			<view class="shop-c-box">选择药房</view>
			<scroll-view scroll-y style="height: 50vh;">
				<view @click="chooseStore(index)" v-for="(item,index) in storeList" :key='index'
					class="rowbox spb c-one-shop">
					<view class="rowbox">
						<image :src="item.logo" mode="aspectFill" class="shop-img"></image>
						<view class="columnbox als">
							<view>{{item.name||'暂无名称'}}</view>
							<view class="shop-address">{{item.province}}{{item.city}}{{item.county}}</view>
						</view>
					</view>
					<u-icon v-if="index==curStore" name="checkmark-circle-fill" color="#00b6b2" size="40rpx"></u-icon>
				</view>
			</scroll-view>
		</u-popup>
	</view>
</template>

<script>
	// 环信即时通讯
	import SDK from 'js_sdk/easemob-im-uni-app/Easemob-chat';
	// 实例化 SDK 对象
	const WebIM = wx.WebIM = SDK;
	import date from '@/utils/time.js'
	export default {
		data() {
			return {
				id: 0,
				typeList: [{
						title: '中药处方'
					},
					{
						title: '西药处方'
					}
				],
				curtype: '中药处方',
				user: null,
				age: 0,
				chufang: {
					name: '',

				}, //处方
				jxList: [], //剂型列表
				submitflag: false,
				yongfaList: ['内服', '外用'],
				curyongfa: '内服',
				specialWrite: false, //特殊写法
				chufangKejian: '1', //购药前处方可见
				// detailPriceList: [], //价格明细列表
				detailPriceFlag: false, //价格明细弹窗
				detailOpen: false, //明细展开
				fuzhenDate: '', //复诊日期
				fuzhenDateflag: false, //选择复诊日期
				silu: '', //思路
				zhenjin: 0, //诊金
				// ycPrice: 0, //药材价格
				ji: 7, //共多少剂
				day: 1,
				ci: 2,
				bianbing: '',
				bianzheng: '',
				title: '',
				jixing: '',
				infoList: [],
				//西药
				zhusu: '', //主诉
				yizhu: '', //医嘱
				kfid: '',
				kftype: '',
				updateinfo: '',
				from: '', //前一页来源
				connectcount: 0,
				selectInputList: [],
				selectInputFlag: false,
				storeList: [], //药店列表
				curStore: 0,
				storeFlag: false,
				totalPrice: 0,
				reOrder: false, //再来一单
			};
		},
		onLoad(options) {
			this.id = parseInt(options.id)
			if (options.kfid) {
				this.kfid = options.kfid * 1
				this.kftype = options.type
				if (options.reOrder) {
					this.reOrder = options.reOrder
				}
			}
			if (options.from) {
				this.from = options.from
			}
			this.getUserInfo()
			this.getStore()
		},
		onShow() {
			if (this.chufang.cfList && this.chufang.cfList.length > 0) {
				this.jixing = this.chufang.Yaofangjixing ? this.chufang.Yaofangjixing[0] : this.jixing
				this.getPriceDetail()
			}
			if (this.infoList.length > 0) {
				let price = 0
				let list = this.infoList
				list.forEach(res => {
					if (!res.use) {
						console.log(res.price)
						res.name = res.medicine
						res.use = {
							price: res.price,
							daynum: res.daynum,
							// kynuit: res.kynuit,
							num: res.num,
							pinci: {
								name: res.pinci
							},
							ylunit: {
								name: res.ylunit
							},
							kynuit: {
								name: res.kynuit
							},
							yongfa: {
								name: res.yongfa,
								num: res.yongliang
							},
							yongliang: res.yongliang
						}
					}
					price += res.price * res.use.num
				})
				this.$set(this.infoList, list)

				this.totalPrice = price.toFixed(2)
			}
		},
		computed: {
			ycPrice() {
				let list = []
				let price = 0
				if (this.chufang.Yaofangdrug) {
					this.chufang.Yaofangdrug.forEach(v => {
						price += v.price * v.gram
						v.name = v.chinesedrug
						list.push(v)
					})
				}
				return price
			},
			detailPriceList() {
				let list = []
				let price = 0
				if (this.chufang.Yaofangdrug) {
					this.chufang.Yaofangdrug.forEach(v => {
						price += v.price * v.gram
						v.name = v.chinesedrug
						list.push(v)
					})
				}
				return list
			},
			// totalPrice() {
			// 	let price = 0
			// 	let list = this.infoList
			// 	if (list.length > 0) {
			// 		for (var i = 0; i < list.length; i++) {
			// 			price += list[i].price * list[i].use.num
			// 		}
			// 	}
			// 	return price.toFixed(2)

			// 	// console.log('====totalPrice========')
			// 	// if (this.curtype == '中药处方') {
			// 	// 	return (this.zhenjin * 1 + this.ycPrice * 1).toFixed(2)
			// 	// } else {
			// 	// 	let price = 0
			// 	// 	let list = this.infoList
			// 	// 	if (list.length > 0) {
			// 	// 		list.forEach(res => {
			// 	// 			price += res.price * res.use.num
			// 	// 		})
			// 	// 	}
			// 	// 	return price.toFixed(2)
			// 	// }
			// },
			doctorInfo() {
				return this.$store.state.user
			},
			// 中药药店有的药材列表
			ycList() {
				let list = []
				if (this.chufang.Yaofangdrug) {
					this.chufang.Yaofangdrug.forEach(res => {
						if (res.price > 0) {
							list.push(res)
						}
					})
				}
				return list
			},
			// 中药药店没有的药材列表
			noYcList() {
				let list = []
				if (this.chufang.Yaofangdrug) {
					this.chufang.Yaofangdrug.forEach(res => {
						if (res.price == 0) {
							list.push(res)
						}
					})
				}
				return list
			}
		},
		methods: {
			inputChoose(type, name) {
				uni.navigateTo({
					url: '/packageA/yaofang/westMedicine/diseaseDiagnosis?type=' + type + '&name=' + name
				})
			},
			showBingLi() {
				uni.navigateTo({
					url: '/pages/patient/detail?id=' + this.id
				})
			},
			chooseStore(index) {
				if (this.curStore != index) {
					this.curStore = index
					if (this.chufang.Yaofangdrug) {
						this.judgeYaoCai()
					}
					// this.chufang = {
					// 	name: ''
					// }
				}
				this.storeFlag = false

				this.$req.post('/doctor/jixinglist', {
					pharmacyid: this.storeList[this.curStore].id * 1
				}).then(res => {
					this.jxList = res.data.data
					if (this.jixing != '') {
						let valueExists = res.data.data.some((item) => {
							return item.id === this.jixing.jixingid
						})
						if (valueExists) {
							res.data.data.forEach((resp, index) => {
								if (resp.id == this.jixing.jixingid) {
									this.jxChange({
										detail: {
											value: index
										}
									})
								}
							})

						} else {
							this.jixing = {
								jixing: this.jxList[0].name,
								jixingid: this.jxList[0].id,
							}
							this.jxChange({
								detail: {
									value: 0
								}
							})
						}
					} else {
						this.jixing = {
							jixing: this.jxList[0].name,
							jixingid: this.jxList[0].id,
						}
						this.jxChange({
							detail: {
								value: 0
							}
						})
					}
				})



			},
			// 获取修改信息
			getUpdateInfo() {
				if (this.kftype == 'zhongyao') {
					this.curtype = '中药处方'
					this.$req.post('/doctor/prescriptioninfo', {
						id: this.kfid
					}).then(res => {
						this.updateinfo = res.data.data
						let v = res.data.data.prescription
						this.bianbing = v.bianbing
						this.bianzheng = v.bianzheng
						this.silu = v.silu
						this.curyongfa = v.state == 1 ? '内服' : '外用'
						this.specialWrite = v.typ == 1 ? true : false
						this.ji = v.ji
						this.day = v.day
						this.ci = v.ci
						this.title = v.title
						this.zhenjin = v.zhenjin
						this.chufangKejian = v.status
						this.fuzhenDate = v.fuzhendate == '' || v.fuzhendate == 0 ? '' : date.couponDate(v
							.fuzhendate)
						this.jixing = {
							jixing: v.jixing,
							jixingid: v.jixingid
						}
						let list = []
						res.data.data.prescriptiondrug.forEach(value => {
							list.push(value.chinesedrug + ' ' + value.gram + 'g')
						})
						this.chufang = {
							name: '处方',
							Yaofangdrug: res.data.data.prescriptiondrug,
							cfList: list
						}
						if (this.storeList.length > 0) {
							for (var i = 0; i < this.storeList.length; i++) {
								if (this.storeList[i].id == this.updateinfo.prescription.pharmacyid) {
									this.curStore = i
									this.judgeYaoCai()
								}
							}
						} else {
							setTimeout(() => {
								for (var i = 0; i < this.storeList.length; i++) {
									if (this.storeList[i].id == this.updateinfo.prescription.pharmacyid) {
										this.curStore = i
										this.judgeYaoCai()
									}
								}
							}, 1000)
						}
					})
				} else {
					this.curtype = '西药处方'
					this.$req.post('/doctor/prescriptionxyinfo', {
						id: this.kfid
					}).then(res => {
						this.updateinfo = res.data.data
						let v = res.data.data.prescriptionxy
						this.zhusu = v.zhusu
						this.bianbing = v.bianbing
						this.yizhu = v.yizhu
						let list = []
						let price = 0
						res.data.data.prescriptionxydrug.forEach(res => {
							price += res.price * res.num
							list.push({
								id: res.medicineid,
								price: res.price,
								use: {
									price: res.price,
									daynum: res.daynum,
									num: res.num,
									pinci: {
										name: res.pinci
									},
									ylunit: {
										name: res.ylunit
									},
									yongfa: {
										name: res.yongfa,
										num: res.yongliang
									},
									yongliang: res.yongliang,
									kynuit: {
										name: res.kynuit
									},
								},
								name: res.medicine,
								image: res.image,
								guige: res.guige
							})
						})

						this.totalPrice = price.toFixed(2)
						this.infoList = list
						// this.totalprice = price
					})
				}
			},

			// 判断药材是否存在
			judgeYaoCai() {
				uni.showLoading({
					title: '加载中'
				})
				let list = this.chufang.Yaofangdrug.map(res => {
					return res.chinesedrug
				})
				this.$req.post('/doctor/yaopinsb', {
					chinesedrugnames: list.join(','),
					pharmacyid: this.storeList[this.curStore].id * 1
				}).then(res => {
					this.chufang.Yaofangdrug.forEach(resp => {
						let valueExists = res.data.data.some(item => {
							return item.name === resp.chinesedrug
						})
						if (valueExists) {
							res.data.data.forEach(v => {
								if (v.name == resp.chinesedrug) {
									resp.price = v.price
									resp.chinesedrugid = v.id
								}
							})
						} else {
							resp.price = 0
						}
					})
					uni.hideLoading()
					this.getPriceDetail()
				})
			},
			changeStore() {
				this.storeFlag = true
			},
			getStore() {
				this.$req.post('/doctor/pharmacys').then(res => {
					this.storeList = res.data.data
					if (this.kfid != '') {
						this.getUpdateInfo()
					}
					setTimeout(() => {
						if (this.updateinfo != '' && this.curtype == '中药处方') {
							for (var i = 0; i < this.storeList.length; i++) {
								if (this.storeList[i].id == this.updateinfo.prescription.pharmacyid) {
									this.curStore = i
									this.getJixing()
								}
							}

						} else {
							this.getJixing()
						}
					}, 1000)
				})
			},
			showSelect() {
				this.selectInputFlag = true
				this.selectInputList = []
			},
			chooseBianbing(v) {
				this.bianbing = v
			},
			hideSelect() {
				setTimeout(() => {
					this.selectInputFlag = false
				}, 100)
			},
			searchSelect(e) {
				this.$req.post('/doctor/jibingsearch', {
					name: e.detail.value
				}).then(res => {
					this.selectInputList = res.data.data || []
				})
			},
			// 修改西药
			updateXiyao() {
				if (this.zhusu == '') {
					uni.showToast({
						title: '请填写主诉',
						icon: 'none'
					})
				} else if (this.bianbing == '') {
					uni.showToast({
						title: '请填写疾病诊断',
						icon: 'none'
					})
				} else if (this.infoList.length == 0) {
					uni.showToast({
						title: '请添加药品',
						icon: 'none'
					})
				} else {
					if (!this.submitflag) {
						this.submitflag = true
						uni.showLoading({
							title: '正在保存'
						})
						let paramer = []
						this.infoList.forEach(res => {
							if (res.use) {
								paramer.push({
									medicineid: Number(res.id),
									yongfa: res.use.yongfa.name,
									pinci: res.use.pinci.name,
									yongliang: res.use.yongliang,
									ylunit: res.use.ylunit.name,
									daynum: Number(res.use.daynum),
									num: Number(res.use.num),
									kynuit: res.use.kynuit.name,
									medicine: res.name,
									image: res.image.split(',')[0],
									guige: res.guige
								})
							}
						})
						this.$req.post('/doctor/prescriptionxyupdate', {
							doctorid: uni.getStorageSync('uid'),
							name: this.user.name,
							jibing: this.bianbing,
							template: 2,
							parameter: JSON.stringify(paramer),
							id: this.kfid,
							// doctorid: uni.getStorageSync('uid'),
							// name: this.user.name,
							// sex: this.user.sex,
							// age: this.age,
							// zhusu: this.zhusu,
							// bianbing: this.bianbing,
							// title: this.yizhu,
							// userid: this.id,
							// yaofangxyid: this.updateinfo.yaofangxyid,
							// id: this.kfid,
							// jibing: this.bianbing,
							// template: 2,
							// parameter: JSON.stringify(paramer)
						}).then(res => {
							uni.hideLoading()
							this.submitflag = false

							if (res.data.code == 0) {
								let pages = getCurrentPages(); //获取所有页面栈实例列表
								let nowPage = pages[pages.length - 1]; //当前页页面实例
								let prevPage = pages[pages.length - 2]; //上一页页面实例
								prevPage.$vm.refreshflag = true
								uni.navigateBack()
							} else {
								uni.showModal({
									title: res.data.msg
								})
							}
						})
					}
				}
			},
			// 修改中药
			updateZhongyao() {
				if (!this.chufang.cfList || this.chufang.cfList.length == 0) {
					uni.showToast({
						title: '请填写处方',
						icon: 'none'
					})
				} else if (this.jixing == '') {
					uni.showToast({
						title: '请选择剂型',
						icon: 'none'
					})
				} else if (this.bianbing == '') {
					uni.showToast({
						title: '请填写辨病',
						icon: 'none'
					})
				} else if (this.bianzheng == '') {
					uni.showToast({
						title: '请填写辨症',
						icon: 'none'
					})
				} else if (this.ji == '') {
					uni.showToast({
						title: '请填写共多少剂',
						icon: 'none'
					})
				} else if (this.day == '') {
					if (this.specialWrite) {
						uni.showToast({
							title: '请填写共服几日',
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: '请填写每日几剂',
							icon: 'none'
						})
					}
				} else if (this.ci == '') {
					if (this.specialWrite) {
						uni.showToast({
							title: '请填写每日分几次服用',
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: '请填写1剂分几次服用',
							icon: 'none'
						})
					}
				} else if (this.noYcList.length > 0) {
					uni.showToast({
						title: '存在缺药药材',
						icon: 'none'
					})
				}
				//  else if (this.zhenjin == '') {
				// 	uni.showToast({
				// 		title: '请填写诊金',
				// 		icon: 'none'
				// 	})
				// } 
				else {
					if (!this.submitflag) {
						this.submitflag = true
						uni.showLoading({
							title: '正在保存'
						})
						let list = []

						this.chufang.Yaofangdrug.forEach(v => {
							list.push({
								chinesedrug: v.chinesedrug,
								chinesedrugid: v.chinesedrugid,
								gram: v.gram
							})
						})
						let data = {
							userid: this.id,
							doctorid: uni.getStorageSync('uid'),
							name: this.user.name,
							sex: this.user.sex,
							age: this.age,
							bianbing: this.bianbing,
							bianzheng: this.bianzheng,
							silu: this.silu,
							yaofangid: this.chufang.id,
							state: this.curyongfa == '内服' ? 1 : 2,
							typ: this.specialWrite ? 1 : 2,
							ji: parseInt(this.ji),
							day: parseInt(this.day),
							ci: parseInt(this.ci),
							title: this.title,
							zhenjin: parseInt(this.zhenjin),
							status: parseInt(this.chufangKejian),
							fuzhen: this.fuzhenDate == '' ? 2 : 1,
							fuzhendate: Date.parse(this.fuzhenDate) / 1000,
							// price: parseFloat(this.totalPrice),
							price: parseFloat((this.zhenjin * 1 + this.ycPrice * this.ji * 1).toFixed(2)),
							parameter: JSON.stringify(list),
							jixing: this.jixing.jixing,
							jixingid: this.jixing.jixingid * 1,
							pharmacyid: this.storeList[this.curStore].id * 1,
							pharmacyname: this.storeList[this.curStore].name,
							pharmacyarea: this.storeList[this.curStore].province +
								this.storeList[this.curStore].city +
								this.storeList[this.curStore].county +
								this.storeList[this.curStore].area,
							id: this.kfid
						}
						this.$req.post('/doctor/prescriptionupdate', data).then(res => {
							uni.hideLoading()
							this.submitflag = false
							if (res.data.code == 0) {
								let pages = getCurrentPages(); //获取所有页面栈实例列表
								let nowPage = pages[pages.length - 1]; //当前页页面实例
								let prevPage = pages[pages.length - 2]; //上一页页面实例
								prevPage.$vm.refreshflag = true
								uni.navigateBack()
							} else {
								uni.showModal({
									title: res.data.msg
								})
							}
						})
					}

				}
			},
			clearChufang() {
				this.chufang = {
					name: ''
				}
			},
			sendMessage(content, classify) {

				// 		"receiveid": this.user.memberid,
				// 		"content": content,
				// 		"classify": classify,
				// 		"nickname": this.user.name,
				// 		"logo": this.user.logo

				let infocontent = {
					classify: classify,
					content: '开方',
					otherid: parseInt(content), //开方ID
					name: this.user.name,
					chatroomheadpic: this.user.logo,
					age: this.age + '',
					sex: this.user.sex + '',
					title: this.bianbing
				}
				let option = {
					type: "txt",
					msg: JSON.stringify(infocontent),
					to: this.user.memberid + "",
					chatType: "singleChat",
				};
				let msg = WebIM.message.create(option);
				getApp().globalData.conn.send(msg).then(res => {
					// uni.hideLoading()
					this.$store.dispatch('actionsHandleNewChatChange', {
						msg: JSON.stringify(infocontent),
						from: this.user.memberid + '',
						time: Date.parse(new Date),
						chatdetailflag: true,
						serverMsgId: res.serverMsgId
					});
					if (this.from == 'chat') {
						uni.hideLoading()
						uni.navigateBack()
					} else {
						setTimeout(() => {
							uni.hideLoading()
							uni.redirectTo({
								url: '/pages/chat/detail?id=' + this.user.memberid
							})
						}, 500)
					}
				}).catch((e) => {
					console.log("==============Send message fail", e);
				});

				// getApp().globalData.chatSocket.send({
				// 	data: JSON.stringify({
				// 		"receiveid": this.user.memberid,
				// 		"content": content,
				// 		"classify": classify,
				// 		"nickname": this.user.name,
				// 		"logo": this.user.logo
				// 	}),
				// 	success: res => {
				// 		console.log('发送成功', res)
				// 		if (this.from == 'chat') {
				// 			// let pages = getCurrentPages(); //获取所有页面栈实例列表
				// 			// let nowPage = pages[pages.length - 1]; //当前页页面实例
				// 			// let prevPage = pages[pages.length - 2]; //上一页页面实例
				// 			// prevPage.$vm.refreshflag = true
				// 			uni.navigateBack()
				// 		} else {
				// 			uni.redirectTo({
				// 				url: '/pages/chat/detail?id=' + this
				// 					.user.memberid
				// 			})
				// 		}
				// 	},
				// 	fail: (err) => {
				// 		console.log('发送失败', err)
				// 		this.reConnect(content, classify)
				// 	}
				// });
			},
			reConnect(content, classify) {
				setTimeout(() => {
					if (this.connectcount < 10) {
						this.connectcount++
						this.sendMessage(content, classify)
					} else {
						this.connectcount = 0
						uni.showToast({
							title: '发送消息失败',
							icon: 'none'
						})
					}
				}, 500)
			},
			deletMedicine(index) {
				this.infoList.splice(index, 1)
			},
			chooseUse(v, index) {
				uni.navigateTo({
					url: '/packageA/yaofang/westMedicine/useType?info=' + JSON.stringify(v) + '&index=' + index
				})
			},
			addMedicine() {
				uni.navigateTo({
					url: '/packageA/yaofang/westMedicine/chooseMedicine'
				})
			},
			//西药处方模版
			chooseWestModel() {
				uni.navigateTo({
					url: '/packageA/yaofang/westMedicine/list'
				})
			},
			//保存西药模版
			saveWestMedicineTem() {
				if (this.infoList.length == 0) {
					uni.showToast({
						title: '请添加药品',
						icon: 'none'
					})
				}
				if (!this.submitflag) {
					this.submitflag = true
					uni.showLoading({
						title: '正在保存'
					})
					let paramer = []
					this.infoList.forEach(res => {
						if (res.use) {
							paramer.push({
								medicineid: Number(res.id),
								yongfa: res.use.yongfa.name,
								pinci: res.use.pinci.name,
								yongliang: res.use.yongliang,
								ylunit: res.use.ylunit.name,
								daynum: Number(res.use.daynum),
								num: Number(res.use.num),
								kynuit: res.use.kynuit.name,
								medicine: res.name,
								image: res.image.split(',')[0],
								guige: res.guige
							})
						}
					})
					this.$req.post('/doctor/yaofangxyadd', {
						doctorid: uni.getStorageSync('uid'),
						name: this.user.name,
						jibing: this.bianbing,
						template: 2,
						parameter: JSON.stringify(paramer)
					}).then(res => {
						uni.hideLoading()
						this.submitflag = false
					})
				}
			},
			submitInfoWestMedicine() {
				if (this.doctorInfo.qianming == '') {
					uni.navigateTo({
						url: '/pages/signature/signature'
					})
					return
				}
				if (this.zhusu == '') {
					uni.showToast({
						title: '请填写主诉',
						icon: 'none'
					})
				} else if (this.bianbing == '') {
					uni.showToast({
						title: '请填写疾病诊断',
						icon: 'none'
					})
				} else if (this.infoList.length == 0) {
					uni.showToast({
						title: '请添加药品',
						icon: 'none'
					})
				} else {
					if (!this.submitflag) {
						this.submitflag = true
						uni.showLoading({
							title: '正在保存'
						})
						let paramer = []
						this.infoList.forEach(res => {
							if (res.use) {
								paramer.push({
									medicineid: Number(res.id),
									yongfa: res.use.yongfa.name,
									pinci: res.use.pinci.name,
									yongliang: res.use.yongliang,
									ylunit: res.use.ylunit.name,
									daynum: Number(res.use.daynum),
									num: Number(res.use.num),
									kynuit: res.use.kynuit.name,
									medicine: res.name,
									image: res.image.split(',')[0],
									guige: res.guige
								})
							}
						})
						this.$req.post('/doctor/yaofangxyadd', {
							doctorid: uni.getStorageSync('uid'),
							name: this.user.name,
							jibing: this.bianbing,
							template: 1,
							parameter: JSON.stringify(paramer)
						}).then(res => {
							this.$req.post('/doctor/prescriptionxyadd', {
								doctorid: uni.getStorageSync('uid'),
								name: this.user.name,
								sex: this.user.sex,
								age: this.age,
								zhusu: this.zhusu,
								bianbing: this.bianbing,
								title: this.yizhu,
								userid: this.id,
								yaofangxyid: res.data.data,
							}).then(res => {
								this.submitflag = false
								if (res.data.code == 0) {
									this.sendMessage(res.data.data + '', 5)
								} else {
									uni.hideLoading()
									uni.showModal({
										title: res.data.msg
									})
								}
							})
						})
					}
				}
			},

			// 中药开方
			submitInfo() {
				if (this.doctorInfo.qianming == '') {
					uni.navigateTo({
						url: '/pages/signature/signature'
					})
					return
				}

				if (!this.chufang.cfList || this.chufang.cfList.length == 0) {
					uni.showToast({
						title: '请填写处方',
						icon: 'none'
					})
				} else if (this.jixing == '') {
					uni.showToast({
						title: '请选择剂型',
						icon: 'none'
					})
				} else if (this.bianbing == '') {
					uni.showToast({
						title: '请填写辨病',
						icon: 'none'
					})
				} else if (this.bianzheng == '') {
					uni.showToast({
						title: '请填写辨症',
						icon: 'none'
					})
				} else if (this.ji == '') {
					uni.showToast({
						title: '请填写共多少剂',
						icon: 'none'
					})
				} else if (this.day == '') {
					if (this.specialWrite) {
						uni.showToast({
							title: '请填写共服几日',
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: '请填写每日几剂',
							icon: 'none'
						})
					}
				} else if (this.ci == '') {
					if (this.specialWrite) {
						uni.showToast({
							title: '请填写每日分几次服用',
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: '请填写1剂分几次服用',
							icon: 'none'
						})
					}
				} else if (this.noYcList.length > 0) {
					uni.showToast({
						title: '存在缺药药材',
						icon: 'none'
					})
				}
				// else if (this.zhenjin == '') {
				// 	uni.showToast({
				// 		title: '请填写诊金',
				// 		icon: 'none'
				// 	})
				// } 
				else {
					if (!this.submitflag) {
						this.submitflag = true
						uni.showLoading({
							title: '正在保存'
						})
						let list = []
						this.chufang.Yaofangdrug.forEach(v => {
							list.push({
								chinesedrug: v.chinesedrug,
								chinesedrugid: v.chinesedrugid,
								gram: v.gram
							})
						})
						let data = {
							userid: this.id,
							doctorid: uni.getStorageSync('uid'),
							name: this.user.name,
							sex: this.user.sex,
							age: this.age,
							bianbing: this.bianbing,
							bianzheng: this.bianzheng,
							silu: this.silu,
							yaofangid: this.chufang.id,
							state: this.curyongfa == '内服' ? 1 : 2,
							typ: this.specialWrite ? 1 : 2,
							ji: parseInt(this.ji),
							day: parseInt(this.day),
							ci: parseInt(this.ci),
							title: this.title,
							zhenjin: parseInt(this.zhenjin),
							status: parseInt(this.chufangKejian),
							fuzhen: this.fuzhenDate == '' ? 2 : 1,
							fuzhendate: Date.parse(this.fuzhenDate) / 1000,
							// price: parseFloat(this.totalPrice),
							price: parseFloat((this.zhenjin * 1 + this.ycPrice * this.ji * 1).toFixed(2)),
							parameter: JSON.stringify(list),
							jixing: this.jixing.jixing,
							jixingid: this.jixing.jixingid * 1,
							pharmacyid: this.storeList[this.curStore].id * 1,
							pharmacyname: this.storeList[this.curStore].name,
							pharmacyarea: this.storeList[this.curStore].province +
								this.storeList[this.curStore].city +
								this.storeList[this.curStore].county +
								this.storeList[this.curStore].area
						}
						this.$req.post('/doctor/prescriptionadd', data).then(res => {
							uni.hideLoading()
							this.submitflag = false
							if (res.data.code == 0) {
								this.sendMessage(res.data.data + '', 4)
							} else {
								uni.hideLoading()
								uni.showModal({
									title: res.data.msg
								})
							}
						})
					}
				}
			},
			getPriceDetail() {
				// let list = []
				// let price = 0
				// this.chufang.Yaofangdrug.forEach(v => {
				// 	price += v.price * v.gram
				// 	v.name = v.chinesedrug
				// 	list.push(v)
				// })
				// this.ycPrice = price
				// this.detailPriceList = list
			},
			//写思路
			writeThink() {
				uni.navigateTo({
					url: '/packageA/yaofang/thinking'
				})
			},
			//选择复诊日期
			confirmFuzhenDate(e) {
				this.fuzhenDate = e[0]
				this.fuzhenDateflag = false
			},
			// 价格明细
			showDetailPrice() {
				if (!this.chufang.cfList || this.chufang.cfList.length == 0) {
					uni.showToast({
						title: '请填写处方',
						icon: 'none'
					})
				} else {
					// this.detailPriceFlag = true
					uni.navigateTo({
						url: '/packageA/yaofang/priceDetail?list=' + JSON.stringify(this.detailPriceList)
					})
				}
			},
			//存模版
			saveModel() {
				if (!this.chufang.Yaofangdrug) {
					uni.showToast({
						title: '请编辑药材',
						icon: 'none'
					})
					return
				}
				if (!this.submitflag) {
					this.submitflag = true
					uni.showModal({
						title: '是否要保存模版',
						success: (res) => {
							if (res.confirm) {
								uni.showLoading({
									title: '正在保存',
									mask: true
								})
								let list = []
								this.chufang.Yaofangdrug.forEach(v => {
									list.push({
										chinesedrug: v.chinesedrug,
										gram: v.gram,
										chinesedrugid: v.chinesedrugid
									})
								})
								this.$req.post('/doctor/yaofangadd', {
									name: '为' + this.user.name + '患者添加药方',
									doctorid: uni.getStorageSync('uid'),
									parameter: JSON.stringify(list),
									jixingid: this.jixing.jixingid,
									jixing: this.jixing.jixing,
								}).then(res => {
									this.submitflag = false
									uni.showToast({
										title: '保存成功',
										icon: 'success'
									})
								})
							} else {
								this.submitflag = false
							}
						}
					})
				}
			},
			//编辑药材
			editYaocai() {
				if (!this.chufang.cfList || this.chufang.cfList.length == 0) {
					uni.navigateTo({
						url: '/packageA/yaofang/editYaocai?sotreId=' + this.storeList[this.curStore].id +
							'&jixingid=' + this.jixing.jixingid
					})
				} else {
					uni.navigateTo({
						url: '/packageA/yaofang/editYaocai?info=' + JSON.stringify(this.chufang) + '&sotreId=' +
							this.storeList[this.curStore].id + '&jixingid=' + this.jixing.jixingid
					})
				}
			},
			// 选择剂型
			jxChange(e) {
				if (this.chufang.Yaofangdrug && this.chufang.Yaofangdrug.length > 0) {
					let list = this.chufang.Yaofangdrug.map(res => {
						return res.chinesedrug
					})
					this.$req.post('/doctor/yaopinjxsb', {
						"chinesedrugnames": list.join(','),
						"pharmacyid": this.storeList[this.curStore].id * 1,
						"jixingid": this.jxList[e.detail.value].id
					}).then(res => {
						this.jixing = {
							jixing: this.jxList[e.detail.value].name,
							jixingid: this.jxList[e.detail.value].id
						}
						let ylist = []
						let newlist = []
						res.data.data.forEach(value => {
							for (var i = 0; i < this.chufang.Yaofangdrug.length; i++) {
								if (value.name == this.chufang.Yaofangdrug[i].chinesedrug) {
									value = Object.assign({}, this.chufang.Yaofangdrug[i], value)
									break;
								}
							}
							value.chinesedrug = value.name
							ylist.push(value.chinesedrug + ' ' + value.gram + 'g')
							newlist.push(value)
						})
						this.chufang = {
							name: '处方',
							Yaofangdrug: newlist,
							cfList: ylist
						}
					})
				} else {
					this.jixing = {
						jixing: this.jxList[e.detail.value].name,
						jixingid: this.jxList[e.detail.value].id
					}
					this.chufang = {
						name: ''
					}
				}
			},
			//剂型列表
			getJixing() {
				this.$req.post('/doctor/jixinglist', {
					pharmacyid: this.storeList[this.curStore].id * 1
				}).then(res => {
					this.jxList = res.data.data
					if (this.jixing != '') {
						let valueExists = res.data.data.some(item => {
							return item.id === this.jixing.jixingid
						})
						if (valueExists) {

						} else {
							this.jixing = {
								jixing: this.jxList[0].name,
								jixingid: this.jxList[0].id,
							}
						}
					} else {
						this.jixing = {
							jixing: this.jxList[0].name,
							jixingid: this.jxList[0].id,
						}
					}
				})
			},

			// 填写处方
			exportChuFang() {
				uni.navigateTo({
					url: '/packageA/yaofang/chufang?storeId=' + this.storeList[this.curStore].id + '&jixing=' +
						this.jixing.jixingid
				})
			},
			getUserInfo() {
				this.$req.post('/doctor/patientinfo', {
					userid: this.id
				}).then(res => {
					this.user = res.data.data.user
					this.getAge(res.data.data.user.shengri)
				})
			},
			getAge(birthday) {
				var today = new Date();
				var birthDate = new Date(birthday);
				var age = today.getFullYear() - birthDate.getFullYear();
				var monthDiff = today.getMonth() - birthDate.getMonth();
				if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
					age--;
				}
				this.age = age - 1;
			},
			// 切换类型
			setType(v) {
				this.curtype = v.title
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background: #F5F8FB;
		justify-content: flex-start;
		font-family: PingFang SC;
	}

	.type-box {
		background: #fff;
		padding: 20rpx 0;

		.one-type {
			width: 170rpx;
			font-weight: bold;
			font-size: 24rpx;
			color: #00b6b2;
			border: #00b6b2 solid 1px;
			height: 62rpx;
		}

		.sel-type {
			color: #fff;
			background: #00b6b2;
		}
	}

	.one-info {
		padding: 32rpx 40rpx;
		background: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
		font-size: 28rpx;
	}

	.q-title {
		font-weight: bold;
		font-size: 28rpx;
		color: #202020;
		font-family: PingFang SC;
		line-height: 40rpx;
		margin-bottom: 20rpx;
	}

	.q-title>view:nth-child(1) {
		position: relative;
		z-index: 4;
	}

	.q-line {
		background: linear-gradient(to right, #00b6b2, rgba(#00b6b2, 0));
		width: 70rpx;
		height: 15rpx;
		margin-top: -15rpx;
	}

	.set-btn {
		font-size: 24rpx;
		font-weight: bold;
	}

	.userinfo {
		font-size: 28rpx;
		color: #232323;
		margin-top: 20rpx;
	}

	.u-input {
		font-size: 28rpx;
		background: #F9F9F9;
		width: 540rpx;
		padding: 20rpx 20rpx;
		// height: 70rpx;
		border-radius: 10rpx;
	}

	.jx-btn {
		color: #fff;
		padding: 10rpx 20rpx;
		border-radius: 4rpx;
	}

	.cf-img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
	}

	.change-btn {
		font-size: 22rpx;
		color: #fff;
		padding: 10rpx 20rpx;
		border-radius: 4rpx;
	}

	.cf-jx {
		min-height: 100rpx;
		width: 400rpx;
		justify-content: space-between;
		font-size: 28rpx;

		.cf-jx-name {
			color: #232323;
			width: 100%;
		}

		.cf-jx-jgmx {
			font-size: 24rpx;
			color: #8998A6;
		}
	}

	.yf-box {
		background: #F9F9F9;
		padding: 32rpx 20rpx;
		border-radius: 10rpx;
		width: 100%;
		margin-top: 0rpx;
		padding-top: 10rpx;

		.wz-detail {
			color: #4c4d4d;
			display: flex;
			flex-wrap: wrap;
			justify-content: flex-start;
		}
	}

	.edit-yc-btn {
		border: #00b6b2 solid 1px;
		width: 100%;
		height: 70rpx;
		margin-top: 40rpx;
		background: rgba(#5bb6ac, .1);
	}

	.one-yongfa {
		margin-top: 20rpx;
		color: #4c4d4d;
		border: rgba(#4c4d4d, 0.2) solid 1px;
		font-size: 24rpx;
		line-height: 40rpx;
		padding: 0 20rpx;
		border-radius: 100rpx;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
	}

	.sel-yongfa {
		color: #00b6b2;
		border: #00b6b2 solid 1px;
	}

	.yongliang-box {
		font-size: 28rpx;
		margin-top: 20rpx;

		.yz-input-box {
			margin: 0 20rpx;
			font-size: 28rpx;
			background: #F9F9F9;
			width: 100rpx;
			padding: 0 20rpx;
			height: 70rpx;
			border-radius: 10rpx;
		}

		input {

			margin: 0 20rpx;
			font-size: 28rpx;
			background: #F9F9F9;
			width: 100rpx;
			padding: 0 20rpx;
			height: 70rpx;
			border-radius: 10rpx;

		}
	}

	.set-box {
		background: #fdf6f6;
		color: #f3523e;
		padding: 10rpx 20rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
		margin-top: 20rpx;
	}

	.jgmx-box {
		padding: 40rpx 32rpx;
	}

	.one-jgmx {
		padding: 20rpx 0;
		border-bottom: #f3f7fa solid 1px;
		color: #232323;
		font-size: 28rpx;
	}

	.draft-btn {
		border: #00b6b2 solid 1px;
		color: #00b6b2;
		width: 200rpx;
		height: 90rpx;
		border-radius: 10rpx;
		background: rgba(#4eb6a9, 0.1);
		font-size: 28rpx;
	}

	.send-btn {
		margin-left: 20rpx;
		width: 500rpx;
		height: 90rpx;
		border-radius: 10rpx;
	}

	.med-info {
		padding: 20rpx 0;
		border-bottom: #F5F7F9 solid 1px;

		.med-title {
			font-size: 24rpx;
			color: #7e9092;
		}

		.del-btn {
			font-size: 24rpx;
			color: #7e9092;
			border: #7e9092 solid 1px;
			width: 100rpx;
			height: 50rpx;
			border-radius: 10rpx;
		}
	}

	.med-box {
		background: #fff;
		width: 100%;
		padding: 32rpx 32rpx;
		border-bottom: #F5F8FB solid 1px;

		.m-img {
			width: 150rpx;
			height: 150rpx;
			border-radius: 10rpx;
		}

		.m-detail {
			width: calc(100% - 170rpx);
			margin-left: 20rpx;
			height: 150rpx;
			justify-content: space-between;
		}

		.m-name {
			font-size: 32rpx;
			font-weight: bold;
		}

		.m-desc {
			font-size: 24rpx;
			color: #7c7d7d;
		}

		.price-info {
			font-size: 32rpx;
			color: #fc2c21;
			font-weight: bold;
		}

		.stock {
			color: #7c7d7d;
			font-size: 24rpx;
			margin-left: 20rpx;
		}

		.one-btn {
			font-size: 24rpx;
			color: #fff;
			padding: 10rpx 20rpx;
			border-radius: 10rpx;
			line-height: 40rpx;
		}
	}

	.add-btn {
		margin-top: 40rpx;
		color: #00b6b2;
		border: #00b6b2 solid 1px;
		height: 70rpx;
		border-radius: 10rpx;
	}

	.cf-name {
		background: #F9F9F9;
		padding: 32rpx 20rpx;
		width: 100%;
		justify-content: flex-start;
		font-size: 32rpx;
		font-weight: bold;

		input {
			margin-left: 10rpx;
			width: 500rpx;
			font-size: 32rpx;
		}
	}

	.manage-box {
		margin-top: 40rpx;
		background: #F9F9F9;
		border-radius: 10rpx;
	}

	.sel-input-box {
		position: relative;

		.select-input-scroll {
			position: absolute;
			background: #fff;
			top: 70rpx;
			z-index: 9;
			max-height: 500rpx;
			border: #F5F7F9 solid 1px;
			box-shadow: #eff1f8 0 0 2px 0;

			.one-select {
				padding: 20rpx;
				border-bottom: #F5F7F9 solid 1px;
				font-size: 28rpx;
			}
		}
	}

	.store-box {
		border-top: #eff3f6 solid 1px;
		padding-top: 20rpx;
		margin-top: 20rpx;
		font-size: 28rpx;

		.change-store {
			margin-left: 20rpx;
		}

		.store-img {
			width: 40rpx;
			height: 40rpx;
			border-radius: 4px;
		}

		.store-name {
			margin-left: 20rpx;
		}
	}

	.shop-c-box {
		padding: 32rpx 0;
		width: 100%;
		text-align: center;
		font-weight: bold;
		font-size: 28rpx;

	}

	.c-one-shop {
		padding: 20rpx 40rpx;
		font-size: 28rpx;
		border-bottom: #F5F7F9 solid 1px;

		.shop-img {
			width: 100rpx;
			height: 100rpx;
			border-radius: 10rpx;
			margin-right: 20rpx;
		}

		.shop-address {
			font-size: 24rpx;
			color: #7c7d7d;
			margin-top: 20rpx;
		}
	}
</style>
<style>
	.reg-pl {
		color: #939BA7;
	}
</style>